(function($) {
	$(document).on('change', ':file', function(e) {
				var $file = $(this);
				$file.parent().prevAll(":text").val($file.val());
			});
	$.zkPost = function(url, data, callback) {
		return $.ajax({
					url : url,
					dataType : 'json',
					contentType : "application/json",
					data : JSON.stringify(data),
					type : 'post',
					async : true,
					success : callback
				});
	};
	$.fn.zk2Json = function(options) {
		var defaults = {
			file_name : 'swws_flzl',
			file_data_key : "zkxx.data.fileJson",
			mx_info : [{
						mx_name : "mx",
						mx_fields : ["mx_input", "mx_input2"]
					}, {
						mx_name : "mx2",
						mx_fields : ["mx2_text", "mx2_text2"]
					}]
		};
		var settings = $.extend({}, defaults, options);
		var form_json = {};
		var a = this.serializeArray();
		$.each(a, function() {
					if (form_json[this.name] !== undefined) {
						if (!form_json[this.name].push) {
							form_json[this.name] = [form_json[this.name]];
						}
						form_json[this.name].push(this.value || '');
					} else {
						form_json[this.name] = this.value || '';
					}
				});
		if (options) {
			var mx_all_fields = new Array();
			$.each(settings.mx_info, function() {
						var mx_first_data = form_json[this.mx_fields[0]];
						var mx_length = 1;
						if ($.isArray(mx_first_data)) {
							mx_length = mx_first_data.length;
						}
						var data_mx = new Array();
						for (var i = 0; i < mx_length; i++) {
							var mx_obj = {};
							var isValidMx = false;
							$.each(this.mx_fields, function() {
										if ($.isArray(form_json[this])) {
											mx_obj[this] = form_json[this][i];
										} else {
											mx_obj[this] = form_json[this];
										}
										if ($.trim(mx_obj[this]).length > 0) {
											isValidMx = true;
										}
									});
							if (isValidMx) {
								data_mx.push(mx_obj);
							}
						}
						form_json[this.mx_name] = data_mx;
						$.merge(mx_all_fields, this.mx_fields);
					});
			$.each(mx_all_fields, function() {
						delete form_json[this];
					});
		}
		var file_obj = $.data(document.body, settings.file_data_key);
		typeof file_obj === 'object'
				&& typeof form_json[settings.file_name] === 'undefined'
				&& (form_json[settings.file_name] = file_obj);
		form_json.calllurl && (delete  form_json.calllurl);
			
				
		return form_json;
	}
})(jQuery);